Repeat With (loopVariable) From (startValue) To (stopValue)
In the Repeat With (loopVariable) From (startValue) To (stopValue) form of the Repeat statement, the looping variable is an integer that is increased by a specified value after each iteration of the loop. The loop terminates when
the value of the variable is greater than a predefined stop value.SYNTAX
repeat with loopVariable from startValue to stopValue [ by stepValue ] [ statement ]... end [ repeat ]whereloopVariable is used to control the number of iterations. It can be any
previously defined variable or a new variable you define in the Repeat statement (see "Notes").startValue (an integer) is the value assigned to loopVariable when the loop
is entered.stopValue (an integer) is the value of loopVariable at which iteration ends. Iteration continues until the value of loopVariable is greater than the value
of stopValue.stepValue (an integer) is the value added to loopVariable after each iteration of the loop. The default value of stepValue is 1.
statement is any AppleScript statement.
EXAMPLE
The following example numbers the paragraphs of a document with the Repeat With (loopVariable) From (startValue) To (stopValue) form of the Repeat statement.
tell document "List" repeat with n from 1 to (count paragraphs) set paragraph n to (n as string) & " " & paragraph n end repeat end tellNOTES
You can use an existing variable as the looping variable in a Repeat statement or define a new one in the Repeat statement. You cannot change the value of the looping variable in the loop body. The variable is undefined after the loop has been executed, but you can redefine it outside the loop.AppleScript evaluates startValue, stopValue, and stepValue when it begins executing the loop and stores the values internally. If you change the values
in the body of the loop, it has no effect on the execution of the loop.